const fs = require("fs")
const path = require("path")

const Stock = require("../../modules/Stock")
const GuoXin = require("../GuoXin")
const $pagination = require("../../utils/pagination")

class QuantitativeTrading {
    static stockStatus = "已收盘"
    static paginationList = []
    static paginationPageIndex = -1
    static stockList = {}
    constructor() {
    }
    async getScanStockList() {
        let result = []

        let { paginationList } = QuantitativeTrading

        if (!paginationList.length) {
            let individualList = await Stock.getIndividualList()
            paginationList = $pagination({ list: individualList })
        }

        if (QuantitativeTrading.paginationPageIndex == paginationList.length - 1) QuantitativeTrading.paginationPageIndex = -1
        QuantitativeTrading.paginationPageIndex++

        result = paginationList[QuantitativeTrading.paginationPageIndex].list


        return result
    }
    updateStockList({ stockList = [] }) {
        stockList.forEach(item => {
            if (!item) return false
            let { code } = item
            QuantitativeTrading.stockList[code] = item
        })
        console.log(QuantitativeTrading.stockList)
    }
}

// let stock = new Stock({ code: "000001", type: "index" })
// setInterval(async () => {
//     let { stockStatus } = await stock.getRealtime({})
//     QuantitativeTrading.stockStatus = stockStatus
// }, 5000)

module.exports = QuantitativeTrading